//var nesromurl="";
kodReady.push(function(){
	Events.bind('explorer.kodApp.before',function(appList){
		const webosUrl = "{{config.webosUrl}}";
		const aliPath = "{{config.aliPath}}";
		if(!webosUrl && !aliPath){
			let cache = localStorage.getItem("tenfellOffice_cacheData");
			if(cache){
				cache = JSON.parse(cache);
				if(cache && cache.expTime > Date.now()){
					localStorage.setItem("tenfellOffice_webosUrl",cache.webosUrl);
					localStorage.setItem("tenfellOffice_aliPath",cache.aliPath);
				}else{
					cache = null;
				}
			}
			if(!cache){
				fetch("https://support.tenfell.cn/wps_token/office.php").then(function (res){return res.json();}).then(function (res){
					res.expTime = Date.now() + 30*60*1000;
					localStorage.setItem("tenfellOffice_webosUrl",res.webosUrl);
					localStorage.setItem("tenfellOffice_aliPath",res.aliPath);
					localStorage.setItem("tenfellOffice_cacheData",JSON.stringify(res));
				});
			}
		}else{
			localStorage.setItem("tenfellOffice_webosUrl",webosUrl);
			localStorage.setItem("tenfellOffice_aliPath",aliPath);
		}
		appList.push({
			name:"腾飞Office",
			title:LNG['admin.plugin.defaulttenfellOffice'],
			icon:'{{pluginHost}}static/image/icon.png',
			ext:"{{config.fileExt}}",
			sort:"{{config.fileSort}}",
			callback:function(path,ext,name){
				var url = '{{pluginApi}}&path='+ encodeURIComponent(path)+'&ext='+encodeURIComponent(ext)+'&name='+encodeURIComponent(name);
					if('window' == "{{config.openWith}}"){
						core.openWindow(url);
					}else{
						core.openDialog(url,core.icon('{{pluginHost}}static/image/icon.png'),"腾飞Office:"+name);
					}
			},
		});
	});
});
